﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sinacor.OMM.HealthMonitor.Entity.Common;

namespace Sinacor.OMM.HealthMonitor.Entity.Router
{
    [Serializable()]
    public class DataBaseProcess : IHealthDataReset
    {

        HealthEntityBase _healthEntityBase;
        public DataBaseProcess()
        {
            _healthEntityBase = new HealthEntityBase();
        }

        public DataBaseProcess(HealthEntityBase healthEntityBase)
        {
            _healthEntityBase = healthEntityBase;
        }

        //Média de Mensagens blocadas para Inserção no DB por vez
        private int _blockProcessingAverageQuantity = -1;
        public int BlockProcessingAverageQuantity
        {
            get { return _blockProcessingAverageQuantity; }
            set 
            { 
                _blockProcessingAverageQuantity = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        //Limite Tempo médio de operação de insert em banco
        private int _limitDataBaseInsertAverageTime = -1;
        public int LimitDataBaseInsertAverageTime
        {
            get { return _limitDataBaseInsertAverageTime; }
            set 
            { 
                _limitDataBaseInsertAverageTime = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        //Tempo médio de operação de insert em banco
        private int _dataBaseInsertAverageTime = -1;
        public int DataBaseInsertAverageTime
        {
            get { return _dataBaseInsertAverageTime; }
            set 
            {
                _dataBaseInsertAverageTime = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        //Número de Re-Conexões com sucesso no BD
        private long _dataBaseSucessfulConnectionRetries = -1;
        public long DataBaseSucessfulConnectionRetries
        {
            get { return _dataBaseSucessfulConnectionRetries; }
            set 
            { 
                _dataBaseSucessfulConnectionRetries = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        //Número de Tentativas Reconexão com Erro no BD
        private long _dataBaseUnsucessfulConnectionRetries = -1;
        public long DataBaseUnsucessfulConnectionRetries
        {
            get { return _dataBaseUnsucessfulConnectionRetries; }
            set 
            { 
                _dataBaseUnsucessfulConnectionRetries = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        //Numero de Mensagens na fila em Banco
        private long _messagesDataBaseQueueQuantity = -1;
        public long MessagesDataBaseQueueQuantity
        {
            get { return _messagesDataBaseQueueQuantity; }
            set 
            {
                _messagesDataBaseQueueQuantity = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        //Limite Numero de Mensagens na fila em Banco
        private long _limitMessagesDataBaseQueueQuantity = -1;
        public long LimitMessagesDataBaseQueueQuantity 
        {
            get { return _limitMessagesDataBaseQueueQuantity; }
            set 
            { 
                _limitMessagesDataBaseQueueQuantity = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        #region IHealthDataReset Members

        public void Reset()
        {
            BlockProcessingAverageQuantity = 0;
            DataBaseInsertAverageTime = 0;
            DataBaseSucessfulConnectionRetries = 0;
            DataBaseUnsucessfulConnectionRetries = 0;
            MessagesDataBaseQueueQuantity = 0;
            LimitDataBaseInsertAverageTime = 0;
            LimitMessagesDataBaseQueueQuantity = 0;
        }

        #endregion
    }
}
